#namespace("com.htwy.core.model.Menu")
  #sql("findByCondition")
    SELECT uuid, name, parentId, type, level, enter, permission, status, serial, creator, createTime, mender, modifyTime, deletedBy, deletedMarker, deleteTime, childrenCount,icon
    FROM ht_sys_menu
    #WHERE()
      #if(uuid)
        uuid = #para(uuid)
      #end
      #if(name)
        AND name = #para(name)
      #end
      #if(parentId)
        AND parentId = #para(parentId)
      #end
      #if(type)
        AND type = #para(type)
      #end
      #if(level)
        AND level = #para(level)
      #end
      #if(enter)
        AND enter = #para(enter)
      #end
      #if(permission)
        AND permission = #para(permission)
      #end
      #if(status)
        AND status = #para(status)
      #end
      #if(serial)
        AND serial = #para(serial)
      #end
      #if(creator)
        AND creator = #para(creator)
      #end
      #if(createTime)
        AND createTime = #para(createTime)
      #end
      #if(mender)
        AND mender = #para(mender)
      #end
      #if(modifyTime)
        AND modifyTime = #para(modifyTime)
      #end
      #if(deletedBy)
        AND deletedBy = #para(deletedBy)
      #end
      #if(deletedMarker)
        AND deletedMarker = #para(deletedMarker)
      #end
      #if(deleteTime)
        AND deleteTime = #para(deleteTime)
      #end
      #if(childrenCount)
        AND childrenCount = #para(childrenCount)
      #end
    #end
    ORDER BY serial asc
    
  #end

  #sql("deleteByPks")
    DELETE FROM ht_sys_menu
    #WHERE()
      #if(pks != null && pks.length > 0)
        #if(pks.length>1)
          uuid in (
          #for(tempId : pks)
            #if(for.first)
              #para(tempId)
            #else
              , #para(tempId)
            #end
          #end
          )
        #else
          uuid = #para(pks[0])
        #end
      #end
    #end
  #end

  #sql("updateChildrenCount")
      UPDATE ht_sys_menu p
      SET p.childrenCount = (SELECT R.CNT FROM
      (SELECT COUNT(c.uuid) CNT FROM ht_sys_menu c WHERE c.parentId = #para(uuid)) R)
      WHERE p.uuid = #para(uuid)
    #end

  #sql("getMaxSerialByParentId")
      SELECT MAX(serial) FROM ht_sys_menu WHERE parentId = #para(parentId)
  #end

#end